home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / INPUT.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  6KB  |  220 lines

  1. ;**********************************;
  2. ; WASM Input Module                ;
  3. ; By Eric Tauck                    ;
  4. ;                                  ;
  5. ; Defines:                         ;
  6. ;                                  ;
  7. ;   InpVer  verify an action       ;
  8. ;   InpEsc  prompt and escape      ;
  9. ;   InpStr  input a string         ;
  10. ;                                  ;
  11. ; Requires:                        ;
  12. ;                                  ;
  13. ;   CASE1.ASM                      ;
  14. ;   KEYBRD.ASM                     ;
  15. ;   PROMPT.ASM                     ;
  16. ;   VIDEO4.ASM                     ;
  17. ;   VIDEO5.ASM                     ;
  18. ;**********************************;
  19.  
  20.         jmp     _input_end
  21.  
  22. ;========================================
  23. ; Display a prompt and wait for a 'Y'
  24. ; for yes or 'N' for no.
  25. ;
  26. ; In: AX= prompt; CL= width.
  27. ;
  28. ; Out: CY= set if cancel ('N' or ESC).
  29.  
  30. InpVer  PROC    NEAR
  31.  
  32. ;--- display prompt
  33.  
  34.         call    ProVer          ;display prompt
  35.         call    KeyClr          ;clear input
  36.  
  37.         mov     al, -1
  38.         call    CurSet          ;cursor on
  39.         push    ax              ;save cursor state
  40.  
  41. ;--- wait for key
  42.  
  43. _ipver1 call    KeyWai          ;wait for key key
  44.         cmp     ax, KEY_ESC     ;check if cancel
  45.         je      _ipver2
  46.         or      ah, ah          ;check if extended code
  47.         jnz     _ipver1
  48.         call    ChrUpr          ;convert to uppercase
  49.         cmp     al, 'N'         ;check if No
  50.         je      _ipver2
  51.         cmp     al, 'Y'         ;check if Yes
  52.         jne     _ipver1
  53.  
  54. ;--- accept
  55.  
  56.         pop     ax
  57.         call    CurSet          ;restore cursor state
  58.         clc
  59.         ret
  60.  
  61. ;--- cancel
  62.  
  63. _ipver2 pop     ax
  64.         call    CurSet          ;restore cursor state
  65.         stc
  66.         ret
  67.         ENDP
  68.  
  69. ;========================================
  70. ; Display a prompt and wait for the ESC
  71. ; key.  Any key except ESC is replaced.
  72.  
  73. InpEsc  PROC    NEAR
  74.  
  75. ;--- display prompt
  76.  
  77.         call    ProEsc          ;display prompt
  78.         call    KeyClr          ;clear input
  79.  
  80. ;--- wait for key
  81.  
  82.         sub     al, al
  83.         call    CurSet          ;cursor off
  84.         push    ax              ;save state
  85.  
  86.         call    KeyWai          ;wait for key
  87.         cmp     ax, KEY_ESC     ;check if escape
  88.         je      _ipesc1         ;skip if so
  89.         call    KeyRep          ;put keystroke back
  90.  
  91. _ipesc1 pop     ax
  92.         call    CurSet          ;restore cursor
  93.         ret
  94.         ENDP
  95.  
  96. ;========================================
  97. ; Input a string.
  98. ;
  99. ; In: AX= prompt; BX= place to store
  100. ;     input; CL= width.
  101. ;
  102. ; Out: AL= byte count; CY= set if no
  103. ;      input or cancel.
  104.  
  105. InpStr  PROC    NEAR
  106.         push    di
  107.         push    si
  108.         push    bp
  109.  
  110.         mov     si, bx          ;home buffer location in SI
  111.  
  112. ;--- display prompt
  113.  
  114.         call    ProWrt          ;display prompt
  115.         dec     ax              ;total characters
  116.         mov     di, ax
  117.  
  118.         call    CurPos          ;get home cursor position
  119.         mov     bp, ax          ;save it
  120.  
  121.         mov     al, -1
  122.         call    CurSet          ;cursor on
  123.         push    ax              ;save state
  124.  
  125.         mov     cx, di          ;max characters in CL
  126.         sub     ch, ch          ;current characters in CH
  127.         mov     di, si          ;current buffer location in DI
  128.  
  129. ;--- get keystroke
  130.  
  131. _ipget1 push    cx
  132.         call    KeyWai          ;wait for a keystroke
  133.         pop     cx
  134.         cmp     ax, KEY_BKSP    ;BACKSPACE
  135.         je      _ipget2
  136.         cmp     ax,KEY_CTL_BKSP ;CTL-BACKSPACE
  137.         je      _ipget3
  138.         cmp     ax, KEY_ESC     ;ESCAPE
  139.         je      _ipget4
  140.         cmp     ax, KEY_ENTER   ;ENTER
  141.         je      _ipget5
  142.         or      ah, ah          ;check if extended key
  143.         jnz     _ipget1
  144.         cmp     al, 32          ;check if control key
  145.         jb      _ipget1
  146.  
  147. ;--- store character
  148.  
  149.         cmp     cl, ch          ;check if too long
  150.         je      _ipget1         ;ignore if so
  151.  
  152.         inc     ch              ;increment bytes
  153.         cld
  154.         stosb                   ;store character
  155.  
  156.         push    cx
  157.         call    WrtChr          ;display character
  158.         call    CurAdv          ;advance cursor
  159.         pop     cx
  160.         jmps    _ipget1
  161.  
  162. ;--- backspace, delete last character
  163.  
  164. _ipget2 or      ch, ch          ;check if any characters
  165.         jz      _ipget1         ;ignore if not
  166.  
  167.         dec     ch              ;decrement bytes
  168.         dec     di              ;decrement pointer
  169.  
  170.         push    cx
  171.         call    CurPos          ;get current position
  172.         dec     al              ;decrement column
  173.         call    CurMov          ;position cursor
  174.         mov     al, ' '         ;space
  175.         call    WrtChr          ;blank last character
  176.         pop     cx
  177.         jmps    _ipget1
  178.  
  179. ;--- ^backspace, delete whole line
  180.  
  181. _ipget3 or      ch, ch          ;check if any characters
  182.         jz      _ipget1         ;ignore if not
  183.  
  184.         mov     di, si          ;reset pointer
  185.         sub     ch, ch          ;zero bytes
  186.  
  187.         push    cx
  188.         push    cx
  189.         mov     ax, bp          ;home position
  190.         call    CurMov          ;move cursor
  191.         pop     cx
  192.         mov     al, ' '         ;space
  193.         inc     cl              ;extra space for end cursor
  194.         call    WrtChrs         ;write characters
  195.         pop     cx
  196.         jmps    _ipget1
  197.  
  198. ;--- escape, cancel input
  199.  
  200. _ipget4 mov     di, si          ;reset pointer
  201.  
  202. ;--- finished with input
  203.  
  204. _ipget5 pop     ax
  205.         call    CurSet          ;restore cursor
  206.  
  207.         mov     BYTE [di], 0    ;store NUL
  208.  
  209.         mov     ax, di          ;current location
  210.         sub     ax, si          ;get bytes
  211.  
  212.         pop     bp
  213.         pop     si
  214.         pop     di
  215.         cmp     ax, 1           ;set carry if no input
  216.         ret
  217.         ENDP
  218.  
  219. _input_end
  220.